<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <style>
        body{
            background-image: url("image/background_Login.jpg");
            background-size: 100%;
        }
    </style>
</head>
<body>
<!--    导航栏-->
<div class="nav">
    <img src="image/person_Blog.png" alt="">
    <span>我的博客系统</span>
    <div class="spacer"></div>
    <a href="list.html">主页</a>
    <a href="edit.html">写博客</a>
</div>

<div class="login-container">
    <div class="login-dialog">
        <h3>注册</h3>
        <div class="row">
            <span>用户名 *</span>
            <input type="text" id="username" onkeyup="this.value=this.value.replace(/[, ]/g,'')">
        </div>
        <div class="row">
            <span>密码 *</span>
            <input type="password" id="password">
        </div>
        <div class="row">
            <span>github</span>
            <input type="text" id="github">
        </div>
        <div class="row">
            <input type="submit" value="提交" id="submit">
        </div>
    </div>
</div>


<script src="jquery.js"></script>
<script>
    let submit = document.querySelector("#submit");
    submit.onclick = function () {
        let username = document.querySelector("#username");
        let password = document.querySelector("#password");
        let github = document.querySelector("#github");
        let user = {
            userName: username.value,
            password: password.value,
            github: github.value
        }
        $.ajax({
            type: 'post',
            url: 'user',
            contentType: "application/json; charset=utf8",
            data: JSON.stringify(user),
            success: function (body) {
                console.log(body)
                if(body == 'null'){
                    alert("用户名或密码不能为空!");
                    location = 'enroll.html';
                }else if(body == 'exist'){
                    alert("该用户已经存在 请重新输入!");
                    location = 'enroll.html';
                }else if(body == "success"){
                    alert("注册成功");
                    location = 'login.html';
                }
            },
            error: function () {
                alert("网络连接错误 请重试!");
                location.assign("enroll.html")
            }
        })
    }
</script>
</body>
</html>